﻿using BaseUI;
using BLL;
using System;
using System.Data;
using System.Web.UI.WebControls;
using Thksoft.Module.DataDetail;

namespace Thksoft.UserCotrols
{
    public partial class PlanDetailSum_Month : BaseControl
    {
        private QS_PLANMONTHAPPLYBLL applyWeekBll = new QS_PLANMONTHAPPLYBLL();
        public DataTable dt;

        protected void Page_Load(object sender, EventArgs e)
        {
            BindDt();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        public void BindDt()
        {
            var pPage = this.Page as ProjectFundDetail_Month;
            HiddenField4.Value = pPage.year;
            HiddenField5.Value = pPage.month;
            dt = new DataTable();
            if (pPage.dtYear != null && pPage.dtYear.Rows.Count > 0 && Convert.ToDecimal(pPage.busId) > 0)
            {
                lblTime.Text = pPage.valTime;
                lblUser.Text = pPage.valUser;
                lblyear.Text = pPage.myDate;
                lbldw.Text = pPage.cmyName;

                lblBzyj.Text = pPage.dtYear.Rows[0]["C_REAMRK"].ToString();
                this.hidId.Value = pPage.dtYear.Rows[0]["N_MONTHAPP_ID"].ToString() + "@" + pPage.busId;

                dt = new QS_PLANMONTHAPPLYBLL().GetDataBind(pPage.busId, lognUser.USER_NAME, pPage.year, pPage.month);
                if (dt != null && dt.Rows.Count > 0)
                {
                    HiddenField3.Value = dt.Rows[0]["N_MONTHAPP_ID"].ToString();
                }
                ViewState["datatable"] = dt;
                gvMonthFunds.DataSource = dt;
                gvMonthFunds.DataBind();
            }
            else
            {
                MessageBox.Show(Page, "【系统提示】没有查询到相关数据集！");
                lblTime.Text = "";
                lblUser.Text = "";
                lblyear.Text = "";
                lblBzyj.Text = "";
                lbldw.Text = "";
                gvMonthFunds.DataSource = dt;
                gvMonthFunds.DataBind();
                return;
            }
        }

        protected void gvMonthFunds_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string type = ((Label)e.Row.FindControl("lbltype")).Text;
                var ifdetails = ((HiddenField)e.Row.FindControl("HiddenField1")).Value == "1" ? true : false;
                string sss = ((Label)e.Row.FindControl("lblProID")).Text;
                if (type == "0")
                {
                    e.Row.Attributes["style"] = "background-color:#B2D8FF;font-size: 14px";
                }
                else if (type == "1")
                {
                    e.Row.Attributes["style"] = "background-color:#CCCCCC;font-size: 13px;";
                }
            }
        }

        /// <summary>
        /// 重新加载数据(子表信息)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //public void ReLoadClick(object sender, EventArgs e)
        //{
        //    foreach (GridViewRow row in gvMonthFunds.Rows)
        //    {
        //        string proId = ((Label)row.FindControl("lblProID")).Text;
        //        string type = ((Label)row.FindControl("lbltype")).Text;
        //        var ifdetails = ((HiddenField)row.FindControl("HiddenField1")).Value == "1" ? true : false;
        //        //if (type == "2" && ifdetails)
        //        //{
        //        //    //查询详情表的值
        //        //    var applyId = Convert.ToInt32(HiddenField3.Value);
        //        //    var sql = "SELECT T1.N_AMOUNT FROM QS_PLANMONTH_DETAIL T1 WHERE T1.N_MONTHAPP_ID={0} AND T1.N_PROID={1}";
        //        //    sql = string.Format(sql, applyId, proId);
        //        //    var dt = new BaseBLL().Query(sql);
        //        //    if (dt.Rows.Count == 0)
        //        //    {
        //        //        //((TextBox)row.FindControl("txtNowMonth")).Text = "0";
        //        //        row.Cells[4].Text = "0";
        //        //    }
        //        //    else
        //        //    {
        //        //        row.Cells[4].Text = dt.Rows[0][0].ToString();
        //        //    }
        //        //    var code = ((HiddenField)row.FindControl("HiddenField2")).Value;
        //        //    row.Cells[4].Attributes.Add("onclick", "FORM_Details(" + HiddenField3.Value + ",2," + proId + ",'" + code + "')");
        //        //    //((TextBox)row.FindControl("txtNowMonth")).ReadOnly = true;
        //        //}
        //    }
        //}

        public void BindDaodu()
        {
            var execll = new BasePage();
            execll.toExecl1(Panel1, "月资金计划申请表" + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString());
        }

        public void BindPrint()
        {
            var key = Guid.NewGuid().ToString();
            //Session[key] = FORM_PRINT_VALUE.Value;
            MessageBox.ResponseScript(Page, "top.MessageBox.Print({Value:\"ID=HTML&VALUE=" + key + "\",Area:[\"800px\",\"500px\"],Scrollbar:true})");
        }
    }
}